package org.example.dao.impl;

import org.example.dao.DepartmentDao;
import org.example.tools.JDBCTool;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class DepartmentDaoImpl implements DepartmentDao {
    @Override
    public Map<String, String> getDepartment() {
        Map<String, String> departMap=new HashMap<>();
        try {
            Connection conn = JDBCTool.getConnection();
            String sql="select * from department";
            PreparedStatement ps =conn.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            while(rs.next()){
                String key = rs.getString("id");
                String value = rs.getString("name");
                departMap.put(key,value);
            }

        }catch (Exception e){
            e.printStackTrace();
        }

        return departMap;

    }
}
